<template>
	<view class="container">
		<view>
			<image src="/static/my_selected.png" style="width: 100px;height: 100px;"></image>
		</view>
		<view class="content">
			<uni-forms ref="form" :model="user" :rules="{}">
				<uni-forms-item label="用户名" name="username">
					<uni-easyinput v-model="user.name" placeholder="请输入用户名"  />
				</uni-forms-item>
				<uni-forms-item label="密码" name="password">
					<uni-easyinput v-model="user.password" placeholder="请输入密码" type="password" />
				</uni-forms-item>
				<uni-forms-item>
					<button type="primary" :plain="true" style="background-color: deepskyblue;"
						@click="login">登录</button>
				</uni-forms-item>
			</uni-forms>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {
					name: '张三',
					password: '123'
				}

			}
		},
		onLoad() {
			uni.onTabBarMidButtonTap(function(e) {
				console.log(e)

			})
		},
		methods: {
			
			login(e) {
				uni.request({
					url: 'http://localhost:8090/freshmenapp/user/login',
					method: 'POST',
					data: this.user,
					success: res => {
						console.log(res.data);
						uni.showToast({
							title: '欢迎您' + res.data.name,
							icon: 'none'
						});
						if (res.data.success) {
							uni.setStorageSync('isLogin', true)
							uni.setStorageSync('user', res.data.data)
							uni.navigateBack()
						} else {
							uni.showToast({
								title: '用户名或者密码错误',
								icon: 'none'
							});
						}
					},
					fail: () => {},
					complete: () => {}
				});
			}
		},
	}
</script>

<style>
	.container {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding-top: 10%;
	}

	.content {
		padding-top: 10%;
		width: 90%;
	}
</style>